<?php

namespace App\Admin\Controllers\code;

use App\Models\CodeNote;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class CodeNoteController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '代码笔记';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new CodeNote());
        $grid->column('code_note_id', __('Code note id'));
        $grid->column('type', __('Type'));
        $grid->column('name', __('Name'));
        $grid->column('js', __('Js'));
        $grid->column('wxss', __('Wxss'));
        $grid->column('wxml', __('Wxml'));
        $grid->column('user_id', __('User id'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));
        $grid->column('deleted_at', __('Deleted at'));
        $grid->column('memo', __('Memo'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(CodeNote::findOrFail($id));

        $show->field('code_note_id', __('Code note id'));
        $show->field('type', __('Type'));
        $show->field('js', __('Js'));
        $show->field('wxss', __('Wxss'));
        $show->field('wxml', __('Wxml'));
        $show->field('user_id', __('User id'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('deleted_at', __('Deleted at'));
        $show->field('memo', __('Memo'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new CodeNote());
        $form->tab('基础',function (Form $form){
            $form->text('name');
            $form->number('type')->default(1);
        });
        $form->tab('php',function (Form $form){
            $form->UEditor('php', __('Js'));
        });
        $form->tab('js',function (Form $form){
            $form->UEditor('js', __('Js'));
        });
        $form->tab('wxss',function (Form $form){
            $form->UEditor('wxss', __('Js'));
        });
        $form->tab('wxml',function (Form $form){
            $form->UEditor('wxml', __('Js'));
        });



        return $form;
    }
}
